/******************************************************************************/
/*                                                                            */
/*  Copyright (c) 2009: ngi-central.org                                       */
/*  All rights reserved.                                                      */
/*                                                                            */
/******************************************************************************/


#include <boost/test/unit_test.hpp>

#include "..\..\include\sgl\direction.h"

BOOST_AUTO_TEST_SUITE( direction3d )


BOOST_AUTO_TEST_CASE( direction3d__default_constructor )
{
	sgl::direction<3> a;

	BOOST_CHECK( a[0] == 0 );
	BOOST_CHECK( a[1] == 0 );


	sgl::direction<3> b(1, 2);

	BOOST_CHECK( b[0] == 1 );
	BOOST_CHECK( b[1] == 2 );
}

BOOST_AUTO_TEST_CASE( direction3d__copy_constructor )
{
	sgl::direction<3> a(sgl::direction<3>(1, 2));

	BOOST_CHECK( a[0] == 1 );
	BOOST_CHECK( a[1] == 2 );
}

BOOST_AUTO_TEST_CASE( direction3d__copy_assignment )
{
	sgl::direction<3> a;
	a = sgl::direction<3>(1, 2);

	BOOST_CHECK( a[0] == 1 );
	BOOST_CHECK( a[1] == 2 );
}

BOOST_AUTO_TEST_CASE( direction3d__swap )
{
	sgl::direction<3> a(0, 1);
	sgl::direction<3> b(2, 3);

	a.swap(b);

	BOOST_CHECK( a[0] == 2 );
	BOOST_CHECK( a[1] == 3 );
	BOOST_CHECK( b[0] == 0 );
	BOOST_CHECK( b[1] == 1 );

	b.swap(a);

	BOOST_CHECK( a[0] == 0 );
	BOOST_CHECK( a[1] == 1 );
	BOOST_CHECK( b[0] == 2 );
	BOOST_CHECK( b[1] == 3 );
}

BOOST_AUTO_TEST_CASE( direction3d__operator_square_brackets )
{
	sgl::direction<3> a;

	BOOST_CHECK_THROW( a[-1], sgl::precondition_violated );
	BOOST_CHECK( a[0] == 0 );
	BOOST_CHECK( a[1] == 0 );
	BOOST_CHECK_THROW( a[2], sgl::precondition_violated );
}

BOOST_AUTO_TEST_CASE( direction3d__phi )
{
	sgl::direction<3> a;

	BOOST_CHECK( a.phi() == 0 );

	a[0] = 1;

	BOOST_CHECK( a.phi() == 1 );
}

BOOST_AUTO_TEST_CASE( direction3d__theta )
{
	sgl::direction<3> a;

	BOOST_CHECK( a.theta() == 0 );

	a[1] = 1;

	BOOST_CHECK( a.theta() == 1 );
}

BOOST_AUTO_TEST_CASE( direction3d__geometric_type )
{
	sgl::direction<3> a;

	BOOST_CHECK( a.type() == sgl::geometric_primitive<>::direction );
}

BOOST_AUTO_TEST_CASE( direction3d__dimensions )
{
	sgl::direction<3> a;

	BOOST_CHECK( a.dimensions() == 3 );
}

BOOST_AUTO_TEST_CASE( direction3d__operator_minus )
{
	sgl::direction<3> a(0, 0);
	sgl::direction<3> b = -a;

	BOOST_CHECK( a[0] == 0 );
	BOOST_CHECK( a[1] == 0 );
	BOOST_CHECK( b[0] == M_PI );
	BOOST_CHECK( b[1] == M_PI );
}

BOOST_AUTO_TEST_CASE( direction3d__operator_equality )
{
	sgl::direction<3> a;
	sgl::direction<3> b;

	BOOST_CHECK( a == b );

	sgl::direction<3> c(1, 2);
	sgl::direction<3> d(1, 2);

	BOOST_CHECK( c == d );
}

BOOST_AUTO_TEST_CASE( direction3d__operator_inequality )
{
	sgl::direction<3> a;
	sgl::direction<3> b(1, 2);

	BOOST_CHECK( a != b );

	sgl::direction<3> c;
	sgl::direction<3> d(1, 2);

	BOOST_CHECK( c != d );
}

BOOST_AUTO_TEST_CASE( direction3d__addition )
{
	sgl::direction<3> a;
	a += sgl::direction<3>(1, 1);

	BOOST_CHECK( a[0] == 1 );
	BOOST_CHECK( a[1] == 1 );

	sgl::direction<3> b(1, 1);
	sgl::direction<3> c(2, 2);
	sgl::direction<3> d = b+c;

	BOOST_CHECK( d[0] == 3 );
	BOOST_CHECK( d[1] == 3 );
}

BOOST_AUTO_TEST_CASE( direction3d__subtraction )
{
	sgl::direction<3> a;
	a -= sgl::direction<3>(1, 1);

	BOOST_CHECK( a[0] == -1 );
	BOOST_CHECK( a[1] == -1 );

	sgl::direction<3> b(1, 1);
	sgl::direction<3> c(2, 2);
	sgl::direction<3> d = b-c;

	BOOST_CHECK( d[0] == -1 );
	BOOST_CHECK( d[1] == -1 );
}

BOOST_AUTO_TEST_CASE( direction3d__scale_multiply )
{
	sgl::direction<3> a(1, 2);
	a *= 2;

	BOOST_CHECK( a[0] == 2 );
	BOOST_CHECK( a[1] == 4 );

	sgl::direction<3> b(1, 2);
	sgl::direction<3> c = b*2;

	BOOST_CHECK( c[0] == 2 );
	BOOST_CHECK( c[1] == 4 );

	sgl::direction<3> d = 2*b;

	BOOST_CHECK( d[0] == 2 );
	BOOST_CHECK( d[1] == 4 );
}

BOOST_AUTO_TEST_CASE( direction3d__scale_divide )
{
	sgl::direction<3> a(2, 4);
	a /= 2;

	BOOST_CHECK( a[0] == 1 );
	BOOST_CHECK( a[1] == 2 );

	sgl::direction<3> b(2, 4);
	sgl::direction<3> c = b/2;

	BOOST_CHECK( c[0] == 1 );
	BOOST_CHECK( c[1] == 2 );
}


BOOST_AUTO_TEST_SUITE_END()

